#include<iostream>
using namespace std;
const int N = 1e6 + 10;
int mp[N];
int n, x;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		int k = x;
		for (int j = 2; j * j <= k; j++) {
			while (x % j == 0) {
				mp[j]++;
				x /= j;
			}
		}
		if (x > 1) {
			mp[x]++;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> x;
		int k = x;
		for (int j = 2; j * j <= k; j++) {
			while (x % j == 0) {
				if (mp[j]) {
					cout << "No" << endl;
					return 0;
				}
				x /= j;
			}
		}
		if (x > 1) {
			if (mp[x]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}